//
//  ScoreKeeperTests.swift
//  ScoreKeeperTests
//
//  Created by Just 花语 on 2025/10/27.
//

import Testing
@testable import AppleDemo
struct ScoreKeeperTests {

    @Test("Reset player scores")
    func resetScores()throws {
        // Write your test here and use APIs like `#expect(...)` to check expected conditions.
        var scoreboard = Scoreboard(players: [
                    Player(name: "Elisha", score: 0),
                    Player(name: "Andre", score: 5),
        ])
        scoreboard.resetScores(to: 0)
        for player in scoreboard.players {
            #expect(player.score == 0)
        }
    }
    
    @Test("Highest score wins")
    func highestScoreWins() {
        let scoreboard = Scoreboard(
            players: [
                Player(name: "Elisha", score: 0),
                Player(name: "Andre", score: 4),
            ],
            state: .gameOver,
            doesHighestScoreWin: true
        )
        let winners = scoreboard.winner
        #expect(winners == [Player(name: "Andre", score: 4)])
    }
    
    @Test("Lowest score wins")
    func lowestScoreWins() {
        let scoreboard = Scoreboard(
            players: [
                Player(name: "Elisha", score: 0),
                Player(name: "Andre", score: 4),
            ],
            state: .gameOver,
            doesHighestScoreWin: false
        )
        let winners = scoreboard.winner
        #expect(winners == [Player(name: "Elisha", score: 0)])
    }

}
